package com.campus.dao.impl;

import com.campus.dao.CourseDao;
import com.campus.model.Course;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class CourseDaoImpl implements CourseDao{
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int createCourse(Course course) {
        try {
            String sql = "INSERT INTO t_manager_course (course_name, created_time, status, activity_id, teacher_id, class_id) " +
                    "VALUES (?, ?, ?, ?, ?, ?)";
            return jdbcTemplate.update(sql,
                    course.getCourseName(),
                    course.getCreatedTime(),
                    course.getStatus(),
                    course.getActivityId(),
                    course.getTeacherId(),
                    course.getClassId());
        } catch (Exception e) {
            System.err.println("Error occurred while creating course: " + e.getMessage());
            return 0;
        }
    }
}
